Find workspace via `workspace_root` link in containing member
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 16 Jan 2017 22:30:59 +0000 (01:30 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 19 Jan 2017 13:09:51 +0000 (16:09 +0300)
src/cargo/core/workspace.rs
tests/workspaces.rs

index fdd14ee23e382febf1777162cfd7604e81dd8fe4..8a4cb0165d01e2f78121d5baa403a832e19b5b8f 100644 (file)
@@ -230,6 +230,14 @@ impl<'cfg> Workspace<'cfg> {
     /// if some other transient error happens.
     fn find_root(&mut self, manifest_path: &Path)
                  -> CargoResult<Option<PathBuf>> {
+        fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult<PathBuf> {
+            let path = member_manifest.parent().unwrap()
+                .join(root_link)
+                .join("Cargo.toml");
+            debug!("find_root - pointer {}", path.display());
+            return Ok(paths::normalize_path(&path))
+        };
+
         {
             let current = self.packages.load(&manifest_path)?;
             match *current.workspace_config() {
@@ -238,11 +246,7 @@ impl<'cfg> Workspace<'cfg> {
                     return Ok(Some(manifest_path.to_path_buf()))
                 }
                 WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
-                    let path = manifest_path.parent().unwrap()
-                                            .join(path_to_root)
-                                            .join("Cargo.toml");
-                    debug!("find_root - pointer {}", path.display());
-                    return Ok(Some(paths::normalize_path(&path)))
+                    return Ok(Some(read_root_pointer(manifest_path, path_to_root)?))
                 }
                 WorkspaceConfig::Member { root: None } => {}
             }
@@ -258,6 +262,9 @@ impl<'cfg> Workspace<'cfg> {
                         debug!("find_root - found");
                         return Ok(Some(manifest))
                     }
+                    WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
+                        return Ok(Some(read_root_pointer(&manifest, path_to_root)?))
+                    }
                     WorkspaceConfig::Member { .. } => {}
                 }
             }
index 1b2797f979d7835a9f17a2492c5c8ad416d11931..dc3860f273a7ae6915deba84d6365a8c1f5012bd 100644 (file)
@@ -1227,8 +1227,7 @@ fn test_path_dependency_under_member() {
 
     assert_that(p.cargo("build").cwd(p.root().join("foo/bar")),
                 execs().with_status(0));
-    // Ideally, `foo/bar` should be a member of the workspace,
-    // because it is hierarchically under the workspace member.
-    assert_that(&p.root().join("foo/bar/Cargo.lock"), existing_file());
-    assert_that(&p.root().join("foo/bar/target"), existing_dir());
+
+    assert_that(&p.root().join("foo/bar/Cargo.lock"), is_not(existing_file()));
+    assert_that(&p.root().join("foo/bar/target"), is_not(existing_dir()));
 }